package com.qing.controller;

import com.qing.dao.NewsDao;
import com.qing.domain.News;
import com.qing.domain.User;
import com.qing.domain.UserLoginLog;
import com.qing.service.LoginLogService;
import com.qing.service.NewsService;
import com.qing.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.List;

@Controller
@RequestMapping("/news")
public class NewsController {
    private final NewsService newsService;
    private final UserService userService;
    private final LoginLogService loginLogService;
    @Autowired
    public NewsController(NewsService newsService,UserService userService,LoginLogService loginLogService){
        this.newsService=newsService;
        this.userService=userService;
        this.loginLogService=loginLogService;
    }

    @RequestMapping("/content-{newsId}")//这个...-{newsId}，只是一个字符串，也要一样
    public String content(@PathVariable int newsId, HttpServletRequest request){
        News news=newsService.getNewsById(newsId);
        if(news==null){return "error";}
        request.setAttribute("news",news);
        return "news/newsContent";
    }

    @RequestMapping(value = "/addNews",method = RequestMethod.POST)
    public String addNews(News newNews){
        newsService.addNews(newNews);
        return"user/userpage";
    }

}
